﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZK.Common;
using ZK.Common.ProModels;

namespace ZK.CoalYardTransManage
{
    public partial class Print : Form
    {
        /// <summary>
        /// 打印的车辆信息
        /// </summary>
        public static TruckYxInfo TruckYxInfo = new TruckYxInfo();

        public Print(string carnum)
        {
            InitializeComponent();
            this.MaximizeBox = false;
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.MinimizeBox = false;


        }
        /// <summary>
        /// 取消按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// 打印磅单对象
        /// </summary>
        ScalesPrint scalesPrint = new ScalesPrint();
        PrintPreviewDialog printPriview = new PrintPreviewDialog();
        /// <summary>
        /// 打印磅单 预览
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(TruckYxInfo.receivingPartyName) && string.IsNullOrWhiteSpace(TruckYxInfo.truckNo))
            {
                MessageBox.Show("数据不能为空!");
                return;
            }
            ScalesPrint.ScalesType scalesType = (ScalesPrint.ScalesType)comboBox2.SelectedIndex;
            string gsmc = comboBox1.SelectedItem.ToString();
            scalesPrint.GSMC = gsmc.Split('-')[1];
            scalesPrint.YF = textBoxYF.Text;
            scalesPrint.TruckYxInfo = TruckYxInfo;
            printPriview = new PrintPreviewDialog
            {
                Document = scalesPrint.printDocument(scalesType),
                WindowState = FormWindowState.Maximized,
            };
            printPriview.Document.BeginPrint += Document_BeginPrint;
            printPriview.ShowDialog();
        }
        /// <summary>
        /// 判断是否打印预览，并关闭打印页面。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Document_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            System.Drawing.Printing.PrintDocument printDocument = sender as System.Drawing.Printing.PrintDocument;
            bool printRes = printDocument.PrintController.IsPreview;
            if (!printRes)
            {
                this.Close();
                printPriview.Close();



            }
        }

        /// <summary>
        /// 页面加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Print_Load(object sender, EventArgs e)
        {

            string[] strArrGsmc = AppConfigHelper.GetAppSettings("gsmc").Split(',');
            for (int i = 0; i < strArrGsmc.Length; i++)
            {
                comboBox1.Items.Add(strArrGsmc[i].Trim());
            }
            comboBox1.SelectedIndex = 0;
            string[] strArrBdlx = AppConfigHelper.GetAppSettings("bdlx").Split(',');
            for (int i = 0; i < strArrBdlx.Length; i++)
            {
                comboBox2.Items.Add(strArrBdlx[i].Trim());
            }
            comboBox2.SelectedIndex = 0;
        }
    }
}
